<%#
不同生活(a@lce.cc)
-%>

<%
	local sys  = require "luci.sys"
	local util = require "luci.util"
	local http = require "luci.http"
	local disp = require "luci.dispatcher"

	local boardinfo = util.ubus("system", "board")

	local request  = disp.context.path
	local request2 = disp.context.request

	local category = request[1]
	local cattree  = category and disp.node(category)

	local leaf = request2[#request2]

	local tree = disp.node()
	local node = disp.context.dispatched

	local categories = disp.node_childs(tree)

	local c = tree
	local i, r

	-- tag all nodes leading to this page
	for i, r in ipairs(request) do
		if c.nodes and c.nodes[r] then
			c = c.nodes[r]
			c._menu_selected = true
		end
	end

    -- send as HTML5
	http.prepare_content("text/html")

	local function nodeurl(prefix, name, query)
		local url = controller .. prefix .. name .. "/"
		if query then
			url = url .. http.build_querystring(query)
		end
		return pcdata(url)
	end

	local function subtree(prefix, node, level)
		if not level then
			level = 1
		end

		local childs = disp.node_childs(node)
		if #childs > 0 then

            if level > 2 then
%>
	<ul class="tabs">
		<%
		end
    local selected_node
    local selected_name
    local i, v

    for i, v in ipairs(childs) do
				local nnode = node.nodes[v]
				if nnode._menu_selected then
					selected_node = nnode
					selected_name = v
				end
                if level > 2 then
		%>
			<li class="tabmenu-item-<%=v%><%- if nnode._menu_selected or (node.leaf and v == leaf) then %> active<% end %>">
			    <a href="<%=nodeurl(prefix, v, nnode.query)%>"><%=striptags(translate(nnode.title))%></a>
			</li>
		<%      end
			end
            if level > 2 then
		%>
	</ul>
<%          end

			if selected_node then
				subtree(prefix .. selected_name .. "/", selected_node, level + 1)
			end
		end
	end
-%>

<html lang="<%=luci.i18n.context.lang%>">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
  <!--[if lt IE 9]><script src="<%=media%>/js/html5.js"></script><![endif]-->
  <script src="<%=media%>/js/prefixfree.min.js" type="text/javascript" ></script>
  <link rel="stylesheet" href="<%=media%>/css/loginstyle.css">
  <link rel="shortcut icon" href="<%=media%>/favicon.ico">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
  <meta name="msapplication-TileImage" content="<%=media%>/images/favicon.png"/>
  <link rel="icon" href="<%=media%>/images/favicon.png" sizes="144x144">
  <link rel="apple-touch-icon-precomposed" href="<%=media%>/images/favicon.png" sizes="144x144">
 </head>

 <body class="lang_<%=luci.i18n.context.lang%> <%- if node then %><%= striptags( node.title ) %><%- end %>">



<% if category then subtree("/" .. category .. "/", cattree) end %>
<div class="lin">
<form method="post" action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
<div class="land_logo"></div>
<div class="input">
				<input class="text_value" name="luci_username" required="required" type="text" value="<%=duser%>" />
				<input class="text_value" name="luci_password" required="required" type="password" placeholder="默认密码butongwifi" />
</div>
        <input type="submit" value="<%:Login%>" class="btn btn-primary btn-block btn-large" />


<%- if fuser then %>
        <div class="error"><%:Invalid username and/or password! Please try again.%></div>
        <br />
<% end -%>

 	</div>
</form>

<script type="text/javascript">//<![CDATA[
	var input = document.getElementsByName('luci_password')[0];
	if (input)
		input.focus();
//]]></script>

<%
local uci  = require "luci.model.uci".cursor()
local fs  = require "nixio.fs"
local https_key = uci:get("uhttpd", "main", "key")
local https_port = uci:get("uhttpd", "main", "listen_https")
if type(https_port) == "table" then
	https_port = https_port[1]
end

if https_port and fs.access(https_key) then
	https_port = https_port:match("(%d+)$")
%>

<script type="text/javascript">//<![CDATA[
	if (document.location.protocol != 'https:') {
		var url = 'https://' + window.location.hostname + ':' + '<%=https_port%>' + window.location.pathname;
		var img=new Image;
		img.onload=function(){window.location = url};
		img.src='https://' + window.location.hostname + ':' + '<%=https_port%>' + '<%=resource%>/cbi/up.gif?' + Math.random();;
		setTimeout(function(){
			img.src=''
		}, 5000);
	}
//]]></script>

<% end %>


